#ifndef __TANK_MSG_OBJ_H__
#define __TANK_MSG_OBJ_H__

#include "render/objs/textobj.h"
#include "render/objs/tankobj.h"
#include "render/objs/bulletobj.h"

class TankMsgObj;
struct TankMsg
{
	bool bTurnRollToAngle;
	float dstRollRadian;

	bool bTurnGunToAngle;
	float dstGunRadian;

	bool bReverseRollAngle;
	bool bRollPositive;

	bool bReverseGunAngle;
	bool bGunPositive;

	bool bSetSpeed;
	float speed;

	bool bSetRollSpeed;
	float rollspeed;

	bool bSetGunSpeed;
	float gunspeed;

	bool bInvincible;
	bool bHheading;
	bool bGo;

	bool bShoot;
};

typedef void (Delegater::*OnTankImpactedFunc)();

#define MAX_BULLET_COUNT 20

class TankMsgObj
{
public:
	TankMsgObj(int id, string strTankName, Point startPos, float startAngle, Color color);
	~TankMsgObj();

	void DoMsg(TankMsg* pMsg);

	//lifepoint become zero
	void DestroyTank();
	
	//tank get
	float GetRollAngle();
	float GetGunAngle();
	bool GetHeading();
	bool GetGo();
	Point GetPos();
	float GetSpeed();
	float GetRollSpeed();
	float GetGunSpeed();

private:
	inline void CalcTextPos();

	//bullet
	void CheckBullet(float differTime);
	inline void InitBullet(BulletObj* pBullet);
	inline BulletObj* GetUsableBullet();

	void OnBeforeRender(float differTime);
	void OnTankModelImpacted();

public:
	Event<OnTankImpactedFunc> OnImpacted;

private:
	//tank obj
	TankObj m_tankObj;
	bool m_bDestroyed;

	//bullets
	BulletObj* m_pBullets[MAX_BULLET_COUNT];
	BulletObj* m_pReadyBullet;
	time_type m_lastBulletTime;
	bool m_bShoot;

	//text
	TextObj m_textObj;
	Point m_textPos;
};

#endif